//
//  View.swift
//  myhub
//
//  Created by x on 2024/5/27.
//

import UIKit
import SnapKit
import XDesignKit

open class View: UIView {

    public convenience init(width: CGFloat) {
        self.init(frame: CGRect(x: 0, y: 0, width: width, height: 0))
        snp.makeConstraints { make in
            make.width.equalTo(width)
        }
    }
    public convenience init(height: CGFloat) {
        self.init(frame: CGRect(x: 0, y: 0, width: 0, height: height))
        snp.makeConstraints { make in
            make.height.equalTo(height)
        }
    }

    public override init(frame: CGRect) {
        super.init(frame: frame)
        makeUI()
    }

    public required init?(coder: NSCoder) {
        super.init(coder: coder)
        makeUI()
    }

    open func makeUI() {
        self.layer.masksToBounds = true
        updateUI()
    }

    open func updateUI() {
        setNeedsDisplay()
    }

    open func getCenter() -> CGPoint {
        return convert(center, from: superview)
    }
}

public extension UIView {
    var inset: CGFloat {
        return Dimensions.inset
    }

    func setPriority(_ priority: UILayoutPriority, for axis: NSLayoutConstraint.Axis) {
        self.setContentHuggingPriority(priority, for: axis)
        self.setContentCompressionResistancePriority(priority, for: axis)
    }
}
